* Reset settings and initialize log file
launch, path("share/evolution")

*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Show how the summer drop has evolved over time.
*-------------------------------------------------------------------------------


* Compute year-by-year summer changes in EPOP by sex
*-------------------------------------------------------------------------------

if "$estimate" != "0" {
	* Load data on adult individuals
	gzuse "$basepath/data/derived/cps_bms_sample.dta.gz", clear

	* Restrict to variables we need
	keep pid tm year month wtfinl female emp

	* Retain observations in May and July
	keep if inlist(month, 5, 7)

	* Aggregate to the cell level
	gcollapse (mean) emp [pw = wtfinl], by(female year month)

	* Compute the change in EPOP from May to July
	keep female year month emp
	reshape wide emp, i(female year) j(month)
	gen demp = 100 * (emp7 - emp5)
	keep female year demp

	* Save the plotting points
	compress
	save "$basepath/models/evolution/plotting.dta", replace
}


* Plot the summer gap over time
*-------------------------------------------------------------------------------

* Prepare recession shading (converting year-months into fractional years)
clear
set obs `=12 * (2019 - 1989 + 1)'
gen int tm = tm(1988m12) + _n
format %tm tm
gen year_adj = year(dofm(tm)) + (month(dofm(tm)) - 6.5)/12
gen byte shading = 1
gen rlow = -2.5
gen rupp = 1
sort tm
tempfile shading
save `shading'

* Load the plotting points
use "$basepath/models/evolution/plotting.dta", clear

* Compute 3-year centered moving averages
egen gid = group(female)
tsset gid year
gen mave = 1/3 * (L1.demp + demp + F1.demp)

* Tack on additional observations for recession shading
append using `shading'

* Plot estimates
#delimit ;
twoway
	(rarea rlow rupp year_adj if shading == 1 & inrange(tm, tm(1990m07), tm(1991m03)), bcolor($ltgs))
	(rarea rlow rupp year_adj if shading == 1 & inrange(tm, tm(2001m03), tm(2001m11)), bcolor($ltgs))
	(rarea rlow rupp year_adj if shading == 1 & inrange(tm, tm(2007m12), tm(2009m06)), bcolor($ltgs))
	(scatteri 0 1989 0 2019, recast(line) color(black))
	(scatter demp year if female == 1, msymbol($sym1) color($col1))
	(line mave year if female == 1, color($col1))
	(scatter demp year if female == 0, msymbol($sym2) color($col2))
	(line mave year if female == 0, color($col2)),
	xtitle("")
	xlabel(1990(5)2020)
	ytitle("May-to-July change in EPOP (p.p.)")
	yscale(range(-2.5 1.0))
	ylabel(-2.5(0.5)1.0)
	plotregion(margin(l=0 r=2 t=0 b=0))
	legend(rows(1) order(5 7 9) label(5 "Women") label(7 "Men"));
#delimit cr

nicepdf "$basepath/output/evolution.pdf", indirect replace

* Close the log file
unlaunch
